package main

import (
	"fmt"
	"log"
	"net"
	"region/grpc"

	"golang.org/x/net/context"
	rpc "google.golang.org/grpc"
	"google.golang.org/grpc/reflection"
)

type server struct{}

func (s *server) SayHello(ctx context.Context, in *grpc.HelloRequest) (reply *grpc.HelloReply, err error) {
	fmt.Println(reply)

	return &grpc.HelloReply{Message: "Hello " + in.Name}, nil
}

type server2 struct{}

func (s *server2) SayHello(ctx context.Context, in *grpc.HelloRequest) (*grpc.HelloReply, error) {
	return &grpc.HelloReply{Message: "I Hello " + in.Name}, nil
}

func main() {
	lis, err := net.Listen("tcp", ":50051")
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}

	s := rpc.NewServer()
	grpc.RegisterGreeterServer(s, &server{})
	grpc.RegisterGreetServer(s, &server2{})
	reflection.Register(s)
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
	log.Println("grpc server started")

}
